package com.hyperfix.washer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyperfix.common.auth.RequiresRole;
import com.hyperfix.models.common.R;
import com.hyperfix.models.washer.dtos.StationDTO;
import com.hyperfix.models.washer.pojos.Pipeline;
import com.hyperfix.models.washer.vos.StationQueryVO;
import com.hyperfix.models.washer.vos.StationVO;
import com.hyperfix.washer.service.StationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author JiangChunYu
 * 2024/4/22
 */
@Validated
@RestController
@RequestMapping("/station")
public class StationController {
    @Resource
    private StationService stationService;

    /**
     * 查询站场
     *
     * @param pageNum       页码
     * @param size          大小
     * @param stationQueryVO 站场查询 VO
     * @return {@link R}<{@link IPage}<{@link StationDTO}>> 查询结果
     */
    @PostMapping("/list/{pageNum}/{size}")
    public R<IPage<StationDTO>> list(@PathVariable @Min(value = 1, message = "页号最小不能小于1") Integer pageNum,
                                     @PathVariable @Min(value = 1, message = "页大小最小不能小于1") Integer size,
                                     @RequestBody @Validated StationQueryVO stationQueryVO) {
        return stationService.list(pageNum, size, stationQueryVO);
    }

    /**
     * 修改站场信息
     *
     * @param stationVO 站场信息 VO
     * @return {@link R}<{@link String}> 是否修改成功
     */
    @RequiresRole("admin")
    @PostMapping("/update")
    public R<String> updateStation(@RequestBody @Validated StationVO stationVO) {
        return stationService.updateStation(stationVO);
    }

    /**
     * 查询指定站场所有管线
     *
     * @param stationId 站场 ID
     * @return {@link R}<{@link List}<{@link Pipeline}>>
     */
    @PostMapping("/listPipeline/{stationId}")
    public R<List<Pipeline>> listPipeline(@PathVariable("stationId") @NotNull Integer stationId) {
        return stationService.listStation(stationId);
    }
}
